package com.pospi.pospihold.util;

import com.pospi.pospihold.dto.CashierMsgDto;
import com.pospi.pospihold.dto.ReturnDto;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;


/**
 * 解析Json
 */
public class PareseJson {

    private CashierMsgDto cashierMsgDto;
    private List<CashierMsgDto> cashierMsgDtos;
    private ReturnDto returnDto=new ReturnDto();

    //解析json数据
    public List<CashierMsgDto> parese(String response) {
        cashierMsgDtos = new ArrayList<>();
        try {
            JSONObject object = new JSONObject(response);
            returnDto.setResult(object.getInt("Result"));
            returnDto.setMessage(object.getString("Message"));
            JSONArray array = object.getJSONArray("Value");
            for (int i = 0; i < array.length(); i++) {
                JSONObject object1 = (JSONObject) array.opt(i);
                cashierMsgDto = new CashierMsgDto();
                cashierMsgDto.setSid(object1.getString("Sid"));
                cashierMsgDto.setUid(object1.getString("UId"));
                cashierMsgDto.setNumber(object1.getString("Number"));
                cashierMsgDto.setName(object1.getString("Name"));
                cashierMsgDto.setPwd(object1.getString("PassWord"));
                cashierMsgDto.setPhone(object1.getString("Phone"));
                cashierMsgDto.setIsAdmin(object1.getInt("IsAdmin"));
//                cashierMsgDto.setIsdel(object1.getBoolean("IsDel"));
//                cashierMsgDto.setShopId(object1.getString("ShopId"));
                cashierMsgDto.setIsAdmin_bool(object1.getBoolean("IsAdmin_bool"));
//                cashierMsgDto.setConfirm(object1.getString("Confirm"));
                cashierMsgDtos.add(cashierMsgDto);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return cashierMsgDtos;
    }
}
